package com.zivwu.library.dao.net.interceptor;

import java.io.IOException;

import okhttp3.FormBody;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;


public class HeadersInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {

        Request oldRequest = chain.request();
        Request request;
        if (oldRequest.body() instanceof FormBody) {
            Request.Builder builder = oldRequest.newBuilder();
            request = builder
                    .addHeader("Content-Type", "application/json")
                    .addHeader("Content-Type", "application/x-www-form-urlencoded")
                    .addHeader("Content-Type", "text/json")
                    .addHeader("Content-Type", "text/javascript")
                    .addHeader("Content-Type", "text/html")
                    .addHeader("Content-Type", "text/plain")
                    .addHeader("Accept", "application/json").build();

        } else {
            request = oldRequest;
        }

        Response response = chain.proceed(request);
        return response;
    }
}
